#include <thread>
#include <future>
#include <chrono>
#include <iostream>

int Add(int num1, int num2)
{
    std::cout << "加法：\n";
    return num1 +num2;
}

int main()
{
    std::cout << "--------1---------\n";
    std::future<int> result = std::async(std::launch::async, Add, 11, 22);
    // std::launch::async 内部创建工作线程，异步执行任务
    // std::launch::deferred 在执行get获取异步结果的时候，才会执行异步任务
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout << "--------2---------\n";
    int sum = result.get();
    std::cout << "--------3---------\n";
    std::cout << sum << std::endl;

    return 0;
}